<template>
  <div class="user-profile" v-if="user">
    <div class="profile-bg"></div>
    <div class="profile-content">
      <div class="avatar-container">
        <el-avatar :size="100" :src="user.avatar" />
        <el-tag class="level-badge" type="warning">{{ user.level || '普通会员' }}</el-tag>
      </div>
      <div class="user-info">
        <h4>{{ user.userNickname }}</h4>
        <div class="stats">
          <div class="stat-item">
            <span class="stat-value">{{ user.userPoint }}</span>
            <span class="stat-label">积分</span>
          </div>
          <div class="stat-item">
            <span class="stat-value">{{ user.coupons }}</span>
            <span class="stat-label">优惠券</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { userAPI } from '@/http'

const user = ref(null)

async function fetchPersonInfo() {
  const response = await userAPI.getUserInfo()
  const data = response.data

  user.value = {
    avatar: data.user.data.userHeading,
    userNickname: data.user.data.userNickname,
    level: '黄金会员', // 固定死的
    userPoint: data.user.data.userPoint,
    coupons: data.couponNum
  }
}

onMounted(() => {
  fetchPersonInfo()
})
</script>

  
  <style scoped>
  .user-profile {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(255, 165, 0, 0.15);
  }
  
  .profile-bg {
    height: 120px;
    background: linear-gradient(135deg, #ffb347, #ffcc33);
  }
  
  .profile-content {
    display: flex;
    align-items: center;
    padding: 0 30px 30px;
    background: white;
    position: relative;
  }
  
  .avatar-container {
    position: relative;
    margin-top: -40px;
    margin-right: 20px;
  }
  
  .level-badge {
    position: absolute;
    bottom: 0;
    right: 0;
  }
  
  .user-info h2 {
    margin: 0 0 10px;
    color: #333;
  }
  
  .stats {
    display: flex;
    gap: 20px;
  }
  
  .stat-item {
    text-align: center;
  }
  
  .stat-value {
    display: block;
    font-size: 18px;
    font-weight: bold;
    color: #ff9500;
  }
  
  .stat-label {
    font-size: 12px;
    color: #888;
  }
  </style>